public class InsertSort {
    public static void main(String[] args) {
        int[] arr = {4,3,5,1,8,2,7,6,9,10};
        insertSort(arr);
        for(int i : arr) {
            System.out.print(i + " ");
        }
    }


    private static void insertSort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            int temp = arr[i];
            int j = i - 1;
            for (; j >= 0; j--) {
                if (arr[j] > temp) {
                    arr[j + 1] = arr[j];
                } else {
                    break;
                }
            }
            arr[j + 1] = temp;
        }
    }

}
